package com.ag.exception;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

public class CodeException extends RuntimeException implements Serializable {
	private static final long serialVersionUID = -448299538034640489L;
	protected Integer code;
	protected String msg;
	protected String detailMsg;
	
	public CodeException(ErrorCode errorCode) {
		this(errorCode.code, errorCode.remark, errorCode.remark);
	}
	
	public CodeException(int code, String msg) {
		this(code, msg, msg);
	}
	
	public Map<String, Object> toMap() {
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", code);
		map.put("msg", msg);
		
		return map;
	}
	
	public CodeException(int code, String msg, String detailMsg) {
		super("Error Code[" + code + "] : " + msg);
		this.code = code;
		this.msg = msg;
		this.detailMsg = detailMsg;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getDetailMsg() {
		return detailMsg;
	}

	public void setDetailMsg(String detailMsg) {
		this.detailMsg = detailMsg;
	}
	
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("[code:").append(this.code).append(",msg:").append(this.msg)
				.append(",detail:").append(this.detailMsg).append("]");
		return buffer.toString();
	}
}
